<?php 
require_once (dirname(__FILE__).'/services.php');



function com_yizin_site_config($matches) {
    global $mvc;
    
    $method = $_SERVER['REQUEST_METHOD'];
    if ($method == 'GET') {
        $GLOBALS['message'] = $mvc->getMessage('message');
        
        $GLOBALS['config'] = site_config_getConfig();
        
        $mvc->render(dirname(__FILE__).'/views/_admin_site_config_.php');
    } elseif ($method == 'POST') {
        $result = site_config_validate();
        
        if (count($result['error']) > 0) {
            $mvc->setMessage('message', '表单中有错误');
            $GLOBALS['message'] = $mvc->getMessage('message');
            
            $GLOBALS['error'] = $result['error'];
            $GLOBALS['config'] = $result['config'];
            $mvc->render(dirname(__FILE__).'/views/_admin_site_config_.php');
            
            return;
        }
        
        
        
        $result['config']['test'] = 'test';
        
        site_config_update($result['config']);
        
        $mvc->setMessage('message', '修改配置成功');
        $mvc->redirect(REQUEST_BASE.'admin/site/config/');
    }
}

/**
 函数对应方法调用
 */
 
global $mvc;
$mvc = new MVC(Array('{^/admin/site/(config/)?$}'=>'com_yizin_site_config',
     ));
$mvc->dispatch($GLOBALS['uri']);

?>
